import ajax, { ListResult, toOptions } from '../ajax';
import { computed, ref } from 'vue';


export function getList(data:any) {
  return ajax.post<ListResult>('/Tags/Subjects/Query', data);
}

export function updateEntity(data:any) {
  if(data.subjectId) {
    return ajax.put<any>('/Tags/Subjects', data);
  } else {
    return ajax.post<any>('/Tags/Subjects', data);
  }
}

export function deleteEntity(id:number) {
  let deleteCommand = {"id": id};
  return ajax.put<any>('/Tags/Subjects/Actions/Delete', deleteCommand);
}

export function getSubjects() {
  let opts = ref([] as SelectOptionData[]);
  setTimeout(async () => {
    let data = await ajax.get(`/Tags/Subjects/Available`);
    opts.value = data.map(a=>{
      return {
        label: a.subjectName,
        value: a.subjectId
      };
    }) as SelectOptionData[];
  }, 1);
  return opts;
}
